package com.trkj.controller;

import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.trkj.service.HwcStaffService;

/**
 * Servlet implementation class HWCLoginTest
 */
@WebServlet("/HWCLoginTest")
public class HWCLoginTest extends HttpServlet {
	private static final long serialVersionUID = 1L;
	private	HwcStaffService	staffService;
    /**
     * @see HttpServlet#HttpServlet()
     */
    public HWCLoginTest() {
        super();
        // TODO Auto-generated constructor stub
        staffService =new HwcStaffService();
    }

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		String account =request.getParameter("account");
		String password =request.getParameter("password");
		boolean pd = staffService.findAccountByStaff(account, password);
		if(pd == true){
			long staffNo =Long.parseLong(account.substring(6));
			String staffName = staffService.findAccountBySName(account);
			request.getSession().setAttribute("account",account); 
			/*mv.addObject("staffAccount", account);
			mv.addObject("staffPassword", password);
			mv.addObject("staffName",staffName);
			mv.addObject("staffNo",staffNo);
			//return "hwc_loginresult";
			
			mv.setViewName("hwc_index");
			*/
			request.setAttribute("staffNo", staffNo);
			request.setAttribute("staffAccount", account);
			request.setAttribute("staffPassword", password);
			request.setAttribute("staffName", staffName);
			request.getRequestDispatcher("/WEB-INF/jsp/hwc_lpgin_test.jsp").forward(request, response);
			
		}else{
			
			//return "yzr_index";
			
			//mv.setViewName("hwc_loginresult");
			
		}
	}

}
